<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>sqlite数据库测试</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.bootcss.com/sql.js/0.5.0/js/sql-optimized.js"></script>
</head>
<body>
        <script>
                // 读取数据库数据
                axios.get("database.db", {responseType: 'arraybuffer'})
                    .then(function (response) {
                        let db = new window.SQL.Database(new Uint8Array(response.data));


                        function findSValue(table,ss,t){ 
                            // 执行查询
                            let s = new Date().getTime();
                            let r = db.exec("SELECT sValue FROM "+table+" where t="+t+" and s="+ss+";");
                            let e = new Date().getTime();
                            console.info("查询数据耗时：" + (e - s) + "ms");
                            // 解析数据
                            //let obj = dbToObj(r);
                            console.info(r[0].values[0][0]);
                            return r[0].values[0][0];
                        }
                        fcuntion 

                        name="电容器"
                        findSValue(0.5,20)
                        findSValue(0.5,25)
                        findSValue(0.2,15)
                        switch(name){
                            case "电容器":{
                                console.log("我是电容器");
                                findSValue("cap_1",0.5,20)
                                break;
                            }
                            case "电阻器":{
                                console.log("电阻器");
                                break;
                            }
                        }

                    })
                    .catch(function (error) {
                        console.info(error);
                    });

        </script>
</body>
</html>